﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BTM_Client_Application.DeviceViewer
{
    /// <summary>
    /// Логика взаимодействия для Container.xaml
    /// </summary>
    public partial class Container : UserControl
    {

        private readonly string _station;
        private readonly string _device;
        public UserControl DeviceControl { get; private set; }

        private Container()
        {
            InitializeComponent();
        }

        public Container(string station, string device, UserControl userControl) : this()
        {
            _station = station;
            _device = device;
            DeviceControl = userControl;
            ContentGrid.Children.Add(userControl);
        }

        public event ControlMiniWinClosed MiniWinClosed;

        protected virtual void OnMiniWinClosed(string station, string device)
        {
            ControlMiniWinClosed handler = MiniWinClosed;
            if (handler != null) handler(station, device);
        }

        public override void OnApplyTemplate()
        {
            DependencyObject d = GetTemplateChild("OmgThereSAButtonOverHere");
            if (d != null)
            {
                (d as Button).Click += OnClick;
            }

            base.OnApplyTemplate();
        }

        private void OnClick(object sender, RoutedEventArgs routedEventArgs)
        {
            OnMiniWinClosed(_station, _device);
        }
    }

    public delegate void ControlMiniWinClosed(string station, string device);
}
